package IC.Symbols;

import IC.SemanticError;
import IC.AST.LocalVariable;
import IC.Types.Type;
import IC.Types.TypeTable;

public class BlockSymbolTable extends SymbolTable {

	private static int uniqueID = 0;

	public BlockSymbolTable(String id, SymbolTable parent) {
		super(id + "[" + uniqueID + "]", id, parent);
		uniqueID++;
	}

	public void insert(LocalVariable var) throws SemanticError{
		String name = var.getName();
		Type type = TypeTable.getType(var);
		VarSymbol symbol = new VarSymbol(name, type, var.getOrder());
		Symbol previous = entries.put(name, symbol);

		if (previous != null){
			throw new SemanticError(var.getLine(), "a local variable with name " + name + " is already defined");
		}
	}

	public String getDisplayString(){
		return "Statement Block Symbol Table ( located in " + parentSymbolTable.name +" )";
	}
}
